
import React from "react";
import { Modal } from 'antd';
import { removeToken } from "@/utils/token";
export class ErrorBoun extends React.Component {

  ErrorMsg!: string;
  constructor(props: {} | Readonly<{}>) {
    super(props);
    this.state = { hasError: false, ErrorMsg: "" };
  }
  static getDerivedStateFromError(error: any) {
    localStorage.setItem("ERRORTWO", error)
    return { hasError: true, ErrorMsg: error ? error.toString() : "NoError" };
  }

  componentDidCatch(error: any, errorInfo: any) {

    localStorage.setItem("ERROR", error)
    localStorage.setItem("errorInfo", JSON.stringify(errorInfo))
  }

  render() {
    if (this.state.ErrorMsg.indexOf("Loading chunk") != -1) {
      // return Modal.info({
      //   title: '当前登录失效,请重新登录',
      //   onOk() {
      //     removeToken()
      //     window.location.replace('/login');
      //   },
      // });
    }

    return this.props.children;
  }
}

  

